/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package objectExtraction;

import com.googlecode.javacv.CanvasFrame;
import com.googlecode.javacv.cpp.opencv_imgproc.*;
import static com.googlecode.javacv.cpp.opencv_core.*;
import static com.googlecode.javacv.cpp.opencv_imgproc.*;

/**
 *
 * @author Shashindra
 */
public class HSVSkinDetector {

    private CvScalar hsv_min = cvScalar(0, 45, 0, 0);
    private CvScalar hsv_max = cvScalar(20, 255, 255, 0);
    private IplImage bacImage;


    public IplImage getHSVSkin(IplImage orgImg) {
        IplImage imgHSV = cvCreateImage(cvGetSize(orgImg), 8, 3);
        IplImage imgThreshold = cvCreateImage(cvGetSize(orgImg), 8, 1);

        cvCvtColor(orgImg, imgHSV, CV_BGR2HSV);
        cvInRangeS(imgHSV, hsv_min, hsv_max, imgThreshold);

        cvSmooth(imgThreshold, imgThreshold, CV_MEDIAN,5);
        IplConvKernel rect_12 = cvCreateStructuringElementEx(3, 3, 1, 1, CV_SHAPE_ELLIPSE, null);
        IplConvKernel rect_6 = cvCreateStructuringElementEx(5, 5, 3, 3, CV_SHAPE_ELLIPSE, null);

        cvMorphologyEx(imgThreshold, imgThreshold, bacImage, rect_6, CV_MOP_CLOSE, 1);
        cvMorphologyEx(imgThreshold, imgThreshold, bacImage, rect_12, CV_MOP_OPEN, 1);


        return imgThreshold;
    }
}
